﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Web.Routing;

namespace AnyGrid.Tests
{
    [TestClass]
    public class GridViewModelTests
    {
        [TestMethod]
        public void GetGridDataActionRouteValue_should_append_GridDataActionSuffix_when_set()
        {
            var currentActionName = "Expected";
            var gvm = new GridViewModel<object>
            {
                GridDataActionSuffix = "Data"
            };
            var expected = currentActionName + gvm.GridDataActionSuffix;

            var actual = gvm.GetGridDataActionRouteValue(currentActionName);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetGridDataActionRouteValue_should_default_to_current_action_name()
        {
            var currentActionName = "Expected";
            var gvm = new GridViewModel<object>();

            var actual = gvm.GetGridDataActionRouteValue(currentActionName);

            Assert.AreEqual(currentActionName, actual);
        }

        [TestMethod]
        public void GetGridDataActionRouteValue_should_use_action_name_in_route_values_if_set_and_GridDataActionNotSet()
        {
            var currentActionName = "NotExpected";
            var rvAction = "Expected";
            var gvm = new GridViewModel<object>
            {
                GridDataRouteValues = new RouteValueDictionary { { "action", rvAction } }
            };

            var actual = gvm.GetGridDataActionRouteValue(currentActionName);

            Assert.AreEqual(rvAction, actual);
        }

        [TestMethod]
        public void GridDataController_should_default_to_current_Controller_name()
        {
            var gvm = new GridViewModel<object>();

            var actual = gvm.GridDataController;

            Assert.IsNull(actual);
        }

        [TestMethod]
        public void GridDataController_should_return_GridDataController_if_set()
        {
            var expected = "Expected";
            var gvm = new GridViewModel<object>
                {
                    GridDataController = expected,
                    GridDataRouteValues = new RouteValueDictionary { { "controller", "NotExpected" } }
                };

            var actual = gvm.GridDataController;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GridDataController_should_return_route_value_if_GridDataController_not_set()
        {
            var expected = "Expected";
            var gvm = new GridViewModel<object>
            {
                GridDataRouteValues = new RouteValueDictionary { { "controller", expected } }
            };

            var actual = gvm.GridDataController;

            Assert.AreEqual(expected, actual);
        }
    }
}
